//package com.yiwei.zhh.service;
//
///**
// * Created by xsooy-pc on 2017/5/10.
// */
//
//import android.annotation.SuppressLint;
//import android.app.Service;
//import android.content.Intent;
//import android.graphics.PixelFormat;
//import android.os.Binder;
//import android.os.IBinder;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.WindowManager;
//import android.view.WindowManager.LayoutParams;
//import android.widget.ImageView;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.yiwei.zhh.R;
//import com.yiwei.zhh.activity.LookPayProcessActivity;
//import com.yiwei.zhh.activity.NewLoanActivity;
//import com.yiwei.zhh.activity.OpinionActivity;
//import com.yiwei.zhh.event.OnLiMuCloseMsg;
//import com.yiwei.zhh.util.PreferenceUtils;
//import com.yiwei.zhh.util.Util;
//import com.yiwei.zhh.view.Dialog;
//
//import org.greenrobot.eventbus.EventBus;
//
//public class FloatViewService extends Service {
//
//    private static final String TAG = "FloatViewService";
//    //定义浮动窗口布局
//    private RelativeLayout mFloatLayout;
//    private WindowManager.LayoutParams wmParams;
//    //创建浮动窗口设置布局参数的对象
//    private WindowManager mWindowManager;
//
//    private TextView mFloatView;
//    public static final int VISIBLE = 1;
//    public static final int GONE = 0;
//    private ImageView mBack;
//
//    @Override
//    public void onCreate() {
//        super.onCreate();
//        Log.i(TAG, "onCreate");
//        createFloatView();
//    }
//
//
//    public class MyBinder extends Binder {
//        public FloatViewService getMyService() {
//            return FloatViewService.this;
//        }
//    }
//
//    public void setTextVisible(int visible) {
//        if (visible == GONE) {
//            mFloatView.setVisibility(View.GONE);
//        } else {
//            mFloatView.setVisibility(View.VISIBLE);
//        }
//    }
//
//    @SuppressWarnings("static-access")
//    @SuppressLint("InflateParams")
//    private void createFloatView() {
//        wmParams = new WindowManager.LayoutParams();
//        //通过getApplication获取的是WindowManagerImpl.CompatModeWrapper
//        mWindowManager = (WindowManager) getApplication().getSystemService(getApplication().WINDOW_SERVICE);
//        //设置window type
////        wmParams.type = LayoutParams.TYPE_PHONE;
////        wmParams.type = LayoutParams.TYPE_TOAST;
//        wmParams.type = LayoutParams.TYPE_SYSTEM_ALERT;
//
//        //设置图片格式，效果为背景透明
//        wmParams.format = PixelFormat.RGBA_8888;
//        //设置浮动窗口不可聚焦（实现操作除浮动窗口外的其他可见窗口的操作）
//        wmParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
//        //调整悬浮窗显示的停靠位置为左侧置顶
//        wmParams.gravity = Gravity.TOP;
////        wmParams.gravity = Gravity.RIGHT | Gravity.TOP;
//        // 以屏幕左上角为原点，设置x、y初始值，相对于gravity
//        wmParams.x = 0;
//        wmParams.y = 0;
//
//        //设置悬浮窗口长宽数据
////        wmParams.width = 490;
//        wmParams.width = LayoutParams.MATCH_PARENT;
//
//        wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//
//        LayoutInflater inflater = LayoutInflater.from(getApplication());
//        //获取浮动窗口视图所在布局
//        mFloatLayout = (RelativeLayout) inflater.inflate(R.layout.float_forget_pwd, null);
//        //添加mFloatLayout
//        mWindowManager.addView(mFloatLayout, wmParams);
//        //浮动窗口按钮
//        mFloatView = (TextView) mFloatLayout.findViewById(R.id.alert_window_imagebtn);
//        mBack = (ImageView) mFloatLayout.findViewById(R.id.left_img);
//
//        mFloatLayout.measure(View.MeasureSpec.makeMeasureSpec(0,
//                View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
//                .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//        //设置监听浮动窗口的触摸移动
////        mFloatView.setOnTouchListener(new OnTouchListener()
////        {
////
////            boolean isClick;
////
////            @SuppressLint("ClickableViewAccessibility") @Override
////            public boolean onTouch(View v, MotionEvent event) {
////                switch (event.getAction()) {
////                    case MotionEvent.ACTION_DOWN:
//////                        mFloatView.setBackgroundResource(R.drawable.circle_red);
////                        isClick = false;
////                        break;
////                    case MotionEvent.ACTION_MOVE:
////                        isClick = true;
////                        // getRawX是触摸位置相对于屏幕的坐标，getX是相对于按钮的坐标
////                        wmParams.x = (int) event.getRawX()
////                                - mFloatView.getMeasuredWidth() / 2;
////                        // 减25为状态栏的高度
////                        wmParams.y = (int) event.getRawY()
////                                - mFloatView.getMeasuredHeight() / 2 - 75;
////                        // 刷新
////                        mWindowManager.updateViewLayout(mFloatLayout, wmParams);
////                        return true;
////                    case MotionEvent.ACTION_UP:
//////                        mFloatView.setBackgroundResource(R.drawable.circle_cyan);
////                        return isClick;// 此处返回false则属于移动事件，返回true则释放事件，可以出发点击否。
////
////                    default:
////                        break;
////                }
////                return false;
////            }
////        });
//
//        mBack.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showCloseDialog();
//            }
//        });
//
//        mFloatView.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                Toast.makeText(FloatViewService.this, "一百块都不给我！", Toast.LENGTH_SHORT).show();
////                if(floatOnClickListener!=null){
////                    floatOnClickListener.onClick();
////                }
//                String url = PreferenceUtils.getString(v.getContext(), "photo_url", "");
//                if (!TextUtils.isEmpty(url)) {
//                    mFloatView.setVisibility(View.GONE);
//                    Intent intent = new Intent(v.getContext(), LookPayProcessActivity.class);
//                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    intent.putExtra("process_url", url);
//                    intent.putExtra("title", "忘记密码");
//                    startActivity(intent);
//                }
//            }
//        });
//    }
//
//
//    //    private FloatOnClickListener floatOnClickListener;
////
////    public interface FloatOnClickListener {
////        void onClick();
////    }
////
////    public void setFloatOnClick(FloatOnClickListener floatOnClickListener) {
////        this.floatOnClickListener = floatOnClickListener;
////    }
//    private void showCloseDialog() {
//        Dialog.showSystemDefaultDialog(this, getResources().getString(R.string.give_up_slot_title), "", getResources().getString(R.string.give_up), getResources().getString(R.string.spurt_text), true, new Dialog.DialogSystemDefaultClickListener() {
//            @Override
//            public void confirm() {
//                EventBus.getDefault().post(new OnLiMuCloseMsg());
//                Intent intent = new Intent(FloatViewService.this, OpinionActivity.class);
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                startActivity(intent);
//                PreferenceUtils.remove(FloatViewService.this, "ReUploadIdCard");
//                stopSelf();
//            }
//
//            @Override
//            public void cancel() {
//                EventBus.getDefault().post(new OnLiMuCloseMsg());
//                Util.getEventCount(getApplicationContext(), "a_jklc_tc");
//                Intent intent = new Intent(FloatViewService.this, NewLoanActivity.class);
//                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                startActivity(intent);
//                stopSelf();
//            }
//
//            @Override
//            public void close() {
//
//            }
//        });
//    }
//
//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        if (mFloatLayout != null) {
//            //移除悬浮窗口
//            mWindowManager.removeView(mFloatLayout);
//        }
//    }
//
//    @Override
//    public IBinder onBind(Intent intent) {
//        return new MyBinder();
//    }
//
//}
